import "dotenv/config";
import { controllers, cors, Nb2, statics } from "nb2";
import { User } from "./controllers/User.js";
import { Relation } from "./controllers/Relation.js";
import { Comment } from "./controllers/Comment.js";
import { Files } from "./controllers/Files.js";
import { Goods } from "./controllers/Goods.js";
import { readFileSync } from "node:fs";
import { posix } from "node:path";

/**https配置 */
export const https = {
  key: readFileSync(
    posix.join(process.env.STATIC_PATH!, "./localhost+1-key.pem")
  ),
  cert: readFileSync(posix.join(process.env.STATIC_PATH!, "localhost+1.pem")),
};

const app = new Nb2({ port: 8080, https });
app.use(cors());
app.use(controllers("/api", User, Goods, Relation, Comment, Files));

app.use(statics(process.env.STATIC_PATH));
app.run();
